<!--
    THIS EXAMPLE WAS DOWNLOADED FROM https://echarts.apache.org/examples/zh/editor.html?c=bar-label-rotation
-->
<!DOCTYPE html>
<html style="height: 100%">

<head>
    <meta charset="utf-8">
</head>

<body style="height: 100%; margin: 0">
    <div id="container" style="height: 100%"></div>


    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script>
    <script src="{{ url_for('static',filename='js/jquery-2.1.1.min.js') }}"></script>


    <script type="text/javascript">
        $(document).ready(function() {
            data = history_date()
            run_echarts(data)
        });

        // 最近几个交易日日期
        function history_date() {
            var r_data = []
            var date = []
            $.ajax({
                url: '/history_date',
                data: {},
                type: 'POST',
                async: false,
                dataType: 'json',
                success: function(data) {

                    for (var i = 0; i < data['date'].length; i++) {
                        var m_data = highest_connection_board_statistics(data['date'][i])
                        r_data.push(m_data)
                        date.push(data['date'][i])
                    }

                },
                error: function(msg) {
                    console.log(msg)
                }
            })
            return {
                data: r_data,
                date: date
            }
        };

        // 最高连板统计
        function highest_connection_board_statistics(date) {
            $.ajax({
                url: '/highest_connection_board_statistics',
                data: {
                    'data': date.replaceAll('-', '') + '  最高连板 去掉ST 去掉新股'
                },
                type: 'POST',
                async: false,
                dataType: 'json',
                success: function(data) {
                    m_data = decode_data(data['data'])
                },
                error: function(msg) {
                    console.log(msg)
                }
            })
            return m_data
        };

        //处理数据
        function decode_data(data) {
            index = data['columns'].indexOf('连续涨停天数')
            console.log(data['data'][0][index])
            return data['data'][0][index]
        }

        function run_echarts(data) {
            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var app = {};

            var option;

            option = {
                tooltip: {
                    trigger: 'axis'
                },
                xAxis: {
                    type: 'category',
                    data: data.date
                },
                yAxis: {
                    type: 'value'
                },
                series: [{
                    data: data.data,
                    type: 'line',
                    smooth: true
                }]
            };

            if (option && typeof option === 'object') {
                myChart.setOption(option);
            }
        }
    </script>
</body>

</html>